package com.demos.springcloud.consumer03HystrixFallback.controller;

import com.demos.springcloud.consumer03HystrixFallback.service.ExceptionProviderService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class controller {

    @Autowired
    private ExceptionProviderService exceptionProviderService;

    @GetMapping("post/exp/{id}")
    @HystrixCommand(fallbackMethod = "method1Fallback")
    public String method1(@PathVariable(name = "id") String id) {
        System.out.println("----------- post exception -------------");
        return exceptionProviderService.expPost(id).toString();
    }

    public String method1Fallback(String id) {
        return "等等";
    }

    @GetMapping("get/exp/timeout")
    @HystrixCommand(fallbackMethod = "method2Fallback")
    public String method2() {
        System.out.println("----------- timeout exception -------------");
        return exceptionProviderService.expGetTO();
    }

    public String method2Fallback() {
        return "method2 fallback";
    }
}
